package com.csdemos.algs;

public class Deque extends Queue {
	
	public Deque() {
		super();
	}

	public Deque(int size) {
		super(size);
	}
	
	public void enqueueFront(int x) {
		if (isFull()) {
			throw new IllegalStateException("Queue is full!");
		}
		head = cycleDecrement(head);
		Q[head] = x;
	}
	
	public int dequeueBack() {
		if (isEmpty()) {
			throw new IllegalStateException("Queue is empty!");
		}
		tail = cycleDecrement(tail);
		return Q[tail];
	}
	
	private int cycleDecrement(int index) {
		return (Q.length + index - 1) % Q.length;
	}

}
